/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file ce_techs.h
 * @brief 卡模拟模块卡片协议相关定义
 */

#ifndef _CE_TECHS_H_
#define _CE_TECHS_H_

#include "nci_feature.h"
#include "nci_base.h"

#if IS_FEATURE_ON(NCI_FEATURE_CE_DH)
#define LF_T3T_IDENTIFIERS_1 0x40
#define LF_T3T_IDENTIFIERS_LEN 0x12
#define LF_T3T_MAX 0x52
#define LF_T3T_FLAGS 0x53
#define LF_T3T_FLAGS_LEN 2
#define LF_T3T_RD_ALLOWED 0x55
#define LF_T3T_RD_ALLOWED_LEN 1

/**
 * @brief T3T信息结构体
 */
typedef struct {
    uint8_t identifier_max;
} tCE_T3T_INFO;

typedef struct {
    /** @brief 系统代码 */
    uint16_t system_code;
    /** @brief NFCID2参数 */
    uint8_t nfcid2[NCI_NFCID2_LEN];
    /** @brief PMM参数 */
    uint8_t pmm[NCI_PMM_LEN];
} tCE_T3T_LISTEN;
#endif // IS_FEATURE_ON(NCI_FEATURE_CE_DH)

/**
 * @brief 卡片操作API定义
 */
typedef struct {
#if IS_FEATURE_ON(NCI_FEATURE_CE_DH)
    /**
     * @brief 注册监听
     *
     * @param[in] id 监听ID
     * @param[in] param 监听参数
     *
     * @return 成功返回NCI_STATUS_OK，失败返回错误码
     */
    tNCI_STATUS (*register_listen)(tNCI_CE_LISTEN_ID *id, tNCI_CE_LISTEN_PARAM *param);
    /**
     * @brief 注销监听
     *
     * @param[in] id 监听ID
     *
     * @return 成功返回NCI_STATUS_OK，失败返回错误码
     */
    tNCI_STATUS (*unregister_listen)(tNCI_CE_LISTEN_ID *id);
#endif // IS_FEATURE_ON(NCI_FEATURE_CE_DH)
    /**
     * @brief 处理接收数据
     *
     * @param[in] p_data 指向接收数据的指针
     * @param[in,out] p_len 接收数据的长度指针
     *
     * @return 成功返回NCI_STATUS_OK，失败返回错误码
     */
    tNCI_STATUS (*receive_handler)(const uint8_t *p_data, uint16_t *p_len);
} tNCI_CE_ACTS;

#if IS_FEATURE_ON(NCI_FEATURE_CE_DH)
/**
 * @brief 初始化T3T模块
 *
 * @return 成功返回NCI_STATUS_OK，失败返回相应的错误码
 */
tNCI_STATUS ce_t3t_init();
#endif // IS_FEATURE_ON(NCI_FEATURE_CE_DH)

#endif /* _CE_TECHS_H_ */
